package study.chapter03.designmodel.singleton;

//单例模式-懒汉式
public class SingletonDemo2 {
    public static void main(String[] args) {
        Singleton2 singleton = Singleton2.getInstance();
        singleton.hello();

    }

}

class Singleton2{
    private static Singleton2 instance;
    private Singleton2(){}

    public static Singleton2 getInstance() {
        if (instance == null){
            instance = new Singleton2();
        }
        return instance;
    }

    public void hello(){
        System.out.println("Hello World! ——单例模式-懒汉式");
    }
}
